package com.xy.tool.data.redis.util;

import java.security.SecureRandom;

public class TimeUtils {

    private final static SecureRandom random = new SecureRandom();

    public static long getExpiredSecondsVariation(long seconds) {
        long value;
        if(seconds < 5) {
            if(random.nextInt() < 0) {
                value = - 1;
            } else {
                value = 1;
            }
        } else if(seconds < 21) {
            value = random.nextInt(5);
        } else if(seconds < 61) {
            value = random.nextInt(10);
        } else if(seconds < 601) {
            value = random.nextInt(30);
        } else {
            value = random.nextInt(60);
        }
        if(value > 0 && random.nextInt() < 0) {
            value = - value;
        }

        return value;
    }


    /// tests

    public static void main(String[] args) {
        System.out.println(getExpiredSecondsVariation(2));
        System.out.println(getExpiredSecondsVariation(20));
        System.out.println(getExpiredSecondsVariation(60));
        System.out.println(getExpiredSecondsVariation(600));
        System.out.println(getExpiredSecondsVariation(610));
    }

}
